<?php
/* ###############################################################################
 *
 * $Id: rss.php 12 2014-09-16 19:04:35Z expertsoftware.i@gmail.com $
 *
 * システム名
 *   PHP Web フレームワーク [Ponzu]
 *
 * 機能
 *   RSS ライブラリ
 *
 * バージョン
 *   0.0.0_0
 *
 * ライセンス
 *   LGPL v2.0
 *
 * 履歴
 *   2007/07/01 K.Sonohara
 *     新規作成。
 *
 * ###############################################################################*/

/**
 * rss出力
 * @access public
 */
function rssBeginEnd($items = null, $title = SITE_TITLE, $desc = SITE_DESCRIPTION, $url = SITE_URL, $rss = SITE_RSS) {
  $image = SITE_URL . "images/logo.png";

  header("Content-type: application/xml; charset=" . SITE_ENCODE);

  beginXML();

  echo '<rdf:RDF';
  echo '  xmlns="http://purl.org/rss/1.0/"';
  echo '  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"';
  echo '  xmlns:dc="http://purl.org/dc/elements/1.1/"';
  echo '  xmlns:content="http://purl.org/rss/1.0/modules/content/"';
  echo '  xml:lang="ja">';

  echo '  <channel rdf:about="' . $rss . '">';
  echo '    <title>' . $title . '</title>';
  echo '    <link>' . $url . '</link>';
  echo '    <dc:date>' . date(DATE_ATOM) . '</dc:date>';
  echo '    <dc:language>ja</dc:language>';
  echo '    <description>' . $desc . '</description>';
  echo '';
  echo '    <image rdf:resource="' . $image . '"/>';
  echo '    <items>';
  echo '      <rdf:Seq>';
  foreach ($items as $k => $v) {
    echo '        <rdf:li rdf:resource="' . $v->about . '"/>';
  }
  echo '      </rdf:Seq>';
  echo '    </items>';
  echo '  </channel>';
  echo '';
  echo '  <image rdf:about="' . $image . '">';
  echo '    <title>' . $title . '</title>';
  echo '    <link>' . $url . '</link>';
  echo '    <url>' . $image . '</url>';
  echo '  </image>';

  foreach ($items as $k => $v) {
    echo '  <item rdf:about="' . $v->about . '">';
    echo '    <title>' . $v->title . '</title>';
    echo '    <link>' . $v->link . '</link>';
    echo '    <dc:creator>' . SITE_TITLE . '</dc:creator>';
    if ($v->datetime != null) {
      echo '    <dc:date>' . date_format(date_create($v->datetime), DATE_ATOM) . '</dc:date>';
    }
    if ($v->description != null) {
      echo '    <description>' . $v->description . '</description>';
    }
    echo '  </item>';
  }
  echo '</rdf:RDF>';
}


class RSSItem {
  var $about = null;
  var $datetime = null;
  var $title = null;
  var $link = null;
  var $description = null;

  function RSSItem($a, $d, $t, $k, $s) {
    $this->about = $a;
    $this->datetime = $d;
    $this->title = $t;
    $this->link = $k;
    $this->description = $s;
  }

}

function SortRSSItem( $a , $b){
  $cmp = strcmp($a->datetime , $b->datetime);
  if( $cmp == 0){
    return strcmp($a->title , $b->title) * -1;
  }
  
  return $cmp * -1;
}
?>
